package com.mobilezu.mobile.pushserver.util;

import java.sql.Connection;
import java.sql.SQLException;

//import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;


public class DBUtil {

	/**
	 * ����ݿ�����
	 * 
	 * @return Connection
	 */
	public static Connection openConn() {

		Connection db_conn = null;// ����JDBC����
		try {
			// ��������ݿ�֮�������
		//	MysqlDataSource
			MysqlDataSource sql_server_ds = new MysqlDataSource();
			sql_server_ds.setServerName(Constants.sqlserver_host);
			sql_server_ds.setPortNumber(Constants.sqlserver_post);
			sql_server_ds.setUser(Constants.sqlserver_user);
			sql_server_ds.setPassword(Constants.sqlserver_passwd);
		//	sql_server_ds.setIntegratedSecurity(false);
			sql_server_ds.setDatabaseName(Constants.sqlserver_db_name);

			db_conn = sql_server_ds.getConnection();
			return db_conn;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;

	}

	/**
	 * �ر���ݿ�����
	 */
	public static void closeConn(Connection conn) {
		try {
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * ������ݿ�����
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Connection c = DBUtil.openConn();
		System.out.println("111");
		DBUtil.closeConn(c);
	}

}
